package com.kunbo.cn.app.controller;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.kunbo.cn.app.entity.Car;
import com.kunbo.cn.app.service.CarService;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

@RestController
@RequestMapping("/car")
public class CarController {
	
	
	@Autowired
	private CarService car;
	
	/**
	 * 保存汽车信息
	 * @param number
	 * @param RFID_number
	 * @param license_plate_number
	 * @param vehicle_type
	 * @param handling_type
	 * @param maximum_payload
	 * @param tare
	 * @param headweight
	 * @param total_traction_weight
	 * @param road_transpor_certificate
	 * @return
	 */
	@PostMapping("/saveCar")
	public ResultBean<Boolean> saveCar(
			@RequestParam("uuid")String uuid,
			@RequestParam("create_user_id")String create_user_id,
			@RequestParam("number")String number,
			@RequestParam("RFID_number")String RFID_number,
			@RequestParam("license_plate_number")String license_plate_number,
			@RequestParam("vehicle_type")String vehicle_type,
			@RequestParam("handling_type")String handling_type,
			@RequestParam("maximum_payload")String maximum_payload,
			@RequestParam("tare")String tare,
			@RequestParam("headweight")String headweight,
			@RequestParam("total_traction_weight")String total_traction_weight,
			@RequestParam("road_transpor_certificate")String road_transpor_certificate,
			@RequestParam("unit")String unit
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", car.saveCar(number, RFID_number, license_plate_number, vehicle_type, handling_type, maximum_payload, tare, headweight, total_traction_weight, road_transpor_certificate,unit,uuid,create_user_id));
	}
	
	
	/**
	 * 修改汽车信息
	 * @param id
	 * @param number
	 * @param RFID_number
	 * @param license_plate_number
	 * @param vehicle_type
	 * @param handling_type
	 * @param maximum_payload
	 * @param tare
	 * @param headweight
	 * @param total_traction_weight
	 * @param road_transpor_certificate
	 * @return
	 */
	@PostMapping("/updateCar")
	public ResultBean<Boolean> updateCar(
			@RequestParam("id")Integer id,
			@RequestParam("number")String number,
			@RequestParam("RFID_number")String RFID_number,
			@RequestParam("license_plate_number")String license_plate_number,
			@RequestParam("vehicle_type")String vehicle_type,
			@RequestParam("handling_type")String handling_type,
			@RequestParam("maximum_payload")String maximum_payload,
			@RequestParam("tare")String tare,
			@RequestParam("headweight")String headweight,
			@RequestParam("total_traction_weight")String total_traction_weight,
			@RequestParam("road_transpor_certificate")String road_transpor_certificate,
			@RequestParam("unit")Integer unit
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", car.updateCar(id,number, RFID_number, license_plate_number, vehicle_type, handling_type, maximum_payload, tare, headweight, total_traction_weight, road_transpor_certificate,unit));
	}
	
	
	/**
	 * 获取某个汽车的信息
	 * @param id
	 * @return
	 */
	@PostMapping("/selById")
	public ResultBean<Car> selById(
			@RequestParam("id")Integer id
			){
		ResultBean<Car> result  = new ResultBean<Car>();
		return BuildBean.buildResult(result, "success", "error", car.selById(id));
	}
	
	
	/**
	 * 获取某个汽车的信息（表单）
	 * @param id
	 * @return
	 */
	@PostMapping("/selByCarId")
	public String selByCarId(
			@RequestParam("id")Integer id
			){
		return car.selByCarId(id);
	}
	
	
	
	/**
	 * 删除汽车
	 * @param id
	 * @return
	 */
	@PostMapping("/delCar")
	public ResultBean<Boolean>  delCar(
			@RequestParam("id")Integer id
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", car.delCar(id));
	}
	
	/**
	 * 汽车列表
	 * @return
	 */
	@PostMapping("/selCar")
	public ResultBean<List<Map<String,Object>>> selCar(
			@RequestParam("wayBillUnit")Integer wayBillUnit,
			@RequestParam("carNumber")String carNumber,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error", car.selCar(carNumber,page,pageSize,wayBillUnit));
	}
	
	
	
	/**
	 * 根据车牌查询
	 * @param carNumber
	 * @return
	 */
	@PostMapping("/selCarBycarNumber")
	public ResultBean<List<Map<String,Object>>> selCarBycarNumber(
			@RequestParam("wayBillUnit")Integer wayBillUnit,
			@RequestParam("carNumber")String carNumber
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "succes", "error", car.selCarNumber(carNumber,wayBillUnit));
	}
}
